package com.tangye.massageshop.controller;

import com.alibaba.fastjson.JSON;
import com.tangye.massageshop.entity.UserEntity;
import com.tangye.massageshop.entity.WorkerEntity;
import com.tangye.massageshop.service.WorkerService;
import com.tangye.massageshop.util.Result;
import com.tangye.massageshop.util.ThreadLocalUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Log4j2
@RestController
@RequestMapping("/worker")
public class WorkerController {

    @Resource
    private WorkerService workerService;

    @PostMapping("/queryWorkerPage")
    public Result<List<WorkerEntity>> queryUserPage(WorkerEntity workerEntity) {
        log.info("入参：{}",JSON.toJSONString(workerEntity));
        UserEntity userSession = ThreadLocalUtil.get();
        workerEntity.setCompanyId(userSession.getCompanyId());
        workerEntity.setShopId(userSession.getShopId());
        List<WorkerEntity> workerEntities = workerService.queryWorkerListPage(workerEntity);
        log.info("反参：{}",JSON.toJSONString(workerEntities));
        return Result.success(workerEntities);
    }

    @PostMapping("/addWorker")
    public Result<String> addWorker(@Validated WorkerEntity workerEntity) {
        workerService.add(workerEntity);
        return Result.ok();
    }

    @PostMapping("/updateWorker")
    public Result<String> updateWorker(WorkerEntity workerEntity) {
        workerService.update(workerEntity);
        return Result.ok();
    }






}
